//
//  LDBossMeHeaderView.swift
//  DingDongZP
//
//  Created by 三秒文化 on 16/6/10.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

import UIKit

class LDBossMeHeaderView: UIView {
    
    
    var model:LDBossBaseInfoModel? {
        
        didSet{
            updataView()
        }
    }
    
    var mysendHeadImg:(()->Void)?
    var mysendMyResume:(()->Void)?
    var mysendEdit:(()->Void)?
    var mysendActivity:(()->Void)?
    var mysendFocus:(()->Void)?
    
    let margin = Margin_V * 5
    var backImgView:UIImageView?
    
    var headViewImg = UIImageView()
    var bossLabDesc = UILabel()
    
    var myPublishBtn:UIButton!
    var editInfoBtn:UIButton!
    
    var publishStatusBgView = UIView()
    var publishStatusImage = UIImageView()
    var publishStatusLabel = UILabel()

    
//    var divideLine:UIView!
//    var btnCover:UIImageView!
    var certifyImgView = UIImageView()
    
    var headImgW:CGFloat = 68
//    //中部信息
//    var activityLab = UILabel()
//    var focusLab = UILabel()
    
//    /// 下标文字
//    lazy var actTitle:UILabel? = {
//        var actTitle = UILabel()
//        actTitle.userInteractionEnabled = true
//        actTitle = UILabel.setDetailsLab("最近活跃度", fontSize: 13, titleColor: LDFontColor.LightGray,Alignment:.Center)
//        return actTitle
//    }()
//    
//    lazy var focTitle:UILabel? = {
//        var focTitle = UILabel()
//        focTitle.userInteractionEnabled = true
//        focTitle = UILabel.setDetailsLab("被关注率", fontSize: 13, titleColor: LDFontColor.LightGray,Alignment:.Center)
//        //        focTitle.userInteractionEnabled = true
//        return focTitle
//    }()
    //遮罩
    lazy var coverView:UIView? = {
        let cover = UIView.init()
        cover.backgroundColor = LDGolbalColor.BgGoundGray
        return cover
    }()
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setContentView()
        setupFrame()
    }
    //
    func updataView() {
        
        let imgurl = LDCommentAPI.getPicApi(model?.logo ?? "default_header")
        headViewImg.sd_setImageWithURL(NSURL(string:imgurl), placeholderImage: UIImage(named:"default_header"))
        
        let bossName = (model?.name ?? "姓名") + " | " + (model?.companyshortname ?? "公司") + " | " + (model?.positioncustomized ?? (model?.positionname ?? "职位"))
        bossLabDesc.text = bossName
        
        if model!.isverified == "1" {
            
            certifyImgView.image = UIImage(named: "已认证_red")
        } else {
            
            certifyImgView.image = UIImage(named: "未认证_gray")
        }
        
        
//        activityLab.text = "\(model!.activeness ?? 0)"
//        focusLab.text = "\(model!.attention ?? 0)%"
        
        // 缓存用户姓名
        DDLoginUserManager.setAccountName(model?.name ?? "(姓名未填写)")
    }
    
    //声明点击的闭包
    
    func sendClickHeadImg(colsure:()->Void) {
        mysendHeadImg = colsure
    }
    
    func sendClickMyResume(colsure:()->Void) {
        mysendMyResume = colsure
    }
    
    func sendClickEditMyResume(colsure:()->Void) {
        mysendEdit = colsure
    }
    
    func sendClickActivityLab(colsure:()->Void) {
        mysendActivity = colsure
    }
    
    func sendClickFocusLab(colsure:()->Void) {
        mysendFocus = colsure
    }
    
    func setContentView() {
        
        //self设置
        self.userInteractionEnabled = true
        backImgView = UIImageView(image: UIImage(named: "header_backgound"))
        headViewImg = UIImageView.setImageView(headImgW/2)
        headViewImg.userInteractionEnabled = true
        headViewImg.image = UIImage(named: "default_header")
        
        bossLabDesc = UILabel.setDetailsLab("性名 | 公司 | 职位", fontSize: 15, titleColor: LDFontColor.White,Alignment:.Center)
        certifyImgView = UIImageView(image: UIImage(named: "未认证_gray"))
        
        addSubview(backImgView!)
        addSubview(bossLabDesc)
        addSubview(certifyImgView)
        
        
//        btnCover = UIImageView()
//        btnCover.userInteractionEnabled = true
//        btnCover.image = UIImage(named: "common_me_header_btncover")
//        divideLine = UIView()
//        divideLine.backgroundColor = UIColor.clearColor()//LDIconColor.LightGray
        
        
        
        //编辑个人信息
        editInfoBtn = UIButton.setBtn(" 编辑信息", picName: "common_me_edit_myresume", btnBackColor: LDGolbalColor.White, titleColor: LDFontColor.Green)
        editInfoBtn.layer.cornerRadius = 0
        
        //马上发布新职位
        myPublishBtn = UIButton.setBtn(" 发布职位", picName: "common_me_edit_profile", btnBackColor: LDGolbalColor.White, titleColor: LDFontColor.Green)
        myPublishBtn.layer.cornerRadius = 0
        
        //
//        publishStatusBtn = UIButton.setBtn(" 成功发布了 0 个职位", picName: "common_me_interview_icon", btnBackColor: LDGolbalColor.White, titleColor: LDFontColor.BlackLight)
        
        publishStatusBgView.backgroundColor = LDGolbalColor.White
        
        publishStatusImage.image = UIImage.init(named:"common_me_interview_icon")

        publishStatusLabel = UILabel.setDetailsLab("成功发布了 0 个职位", fontSize: 15, titleColor:LDFontColor.BlackLight,Alignment:.Left)

        
//        btnCover.addSubview(divideLine)
//        btnCover.addSubview(myPublishBtn)
//        btnCover.addSubview(editInfoBtn)
        
        addSubview(coverView!)
        addSubview(headViewImg)
        addSubview(myPublishBtn)
        addSubview(editInfoBtn)
        addSubview(publishStatusBgView)
        publishStatusBgView.addSubview(publishStatusImage)
        publishStatusBgView.addSubview(publishStatusLabel)
        
//        addSubview(btnCover)
        
        
//        activityLab = UILabel.setDetailsLab("0", fontSize: 30, titleColor: LDFontColor.BlackLight
//            ,Alignment: NSTextAlignment.Center)
//        activityLab.userInteractionEnabled = true
//        
//        focusLab = UILabel.setDetailsLab("0%", fontSize: 30, titleColor: LDFontColor.BlackLight,Alignment: NSTextAlignment.Center)
//        focusLab.userInteractionEnabled = true
//        //
//        focTitle?.userInteractionEnabled = true
//        actTitle?.userInteractionEnabled = true
        
        
        
//        addSubview(actTitle!)
//        addSubview(focTitle!)
//        addSubview(activityLab)
//        addSubview(focusLab)
        
        
        //点击图片
        headViewImg.bk_whenTapped() { [weak self] in
            if self?.mysendHeadImg != nil {
                self?.mysendHeadImg!()
            }
        }
        //发布职位
        myPublishBtn.bk_whenTapped() {
            [weak self] in
            if self?.mysendMyResume != nil {
                self?.mysendMyResume!()
            }
        }
        //编辑个人信息
        editInfoBtn.bk_whenTapped() {
            [weak self] in
            if self?.mysendEdit != nil {
                self?.mysendEdit!()
            }
        }
//        //点击活跃度
//        activityLab.bk_whenTapped() {
//            [weak self] in
//            if self?.mysendActivity != nil {
//                self?.mysendActivity!()
//            }
//        }
//        
//        //点击活跃度title
//        actTitle!.bk_whenTapped() {
//            [weak self] in
//            
//            if self?.mysendActivity != nil {
//                self?.mysendActivity!()
//            }
//        }
//        
//        //点击被关注率
//        focusLab.bk_whenTapped() {
//            [weak self] in
//            
//            if self?.mysendFocus != nil {
//                self?.mysendFocus!()
//            }
//        }
//        
//        focTitle!.bk_whenTapped() {
//            
//            [weak self] in
//            if self?.mysendFocus != nil {
//                self?.mysendFocus!()
//            }
//        }
    }
    //分散 布局
    func setupFrame() {
        
        backImgView!.snp_makeConstraints { (make) in
            
//            make.top.left.right.equalTo(0)
//            make.bottom.equalTo(-80)
            make.top.left.right.equalTo(0)
            make.bottom.equalTo(-135)
        }
        
        //上部布局
        headViewImg.snp_makeConstraints { (make) in
            
            make.centerX.equalTo(self)
            make.height.width.equalTo(headImgW)
            make.bottom.equalTo(bossLabDesc.snp_top).offset(-LDMargin_V*3)
        }
        
        bossLabDesc.snp_makeConstraints { (make) in
            
            make.centerX.equalTo(headViewImg)
            make.height.equalTo(25)
            make.bottom.equalTo(backImgView!.snp_bottom).offset(-LDMargin_V*6)
        }
        
        certifyImgView.snp_makeConstraints { (make) in
            
            make.centerX.equalTo(headViewImg)
            make.height.equalTo(18)
            make.width.equalTo(65)
//            make.bottom.equalTo(btnCover.snp_top).offset(-LDMargin_V*3)
        }
        
//        btnCover.snp_makeConstraints { (make) in
//            make.centerX.equalTo(self)
//            make.height.equalTo(60)
//            make.left.right.equalTo(0)
//            make.bottom.equalTo(coverView!.snp_top)//.offset(-LDMargin_V*2)
//        }
        
//        divideLine.snp_makeConstraints { (make) in
//            
//            make.centerX.equalTo(self)
//            make.top.equalTo(5)
//            make.bottom.equalTo(-5)
//            make.width.equalTo(0.5)
//        }
        

        
        editInfoBtn.snp_makeConstraints { (make) in
//            make.top.right.bottom.equalTo(0)
//            make.left.equalTo(divideLine.snp_right)
            
            make.top.equalTo(backImgView!.snp_bottom).offset(LDMargin_V*2)
            make.left.equalTo(0)
            make.height.equalTo(54)
            make.right.equalTo(self.snp_centerX).offset(-3)
            
        }
        
        myPublishBtn.snp_makeConstraints { (make) in
            //            make.top.left.bottom.equalTo(0)
            //            make.right.equalTo(divideLine.snp_left)
            make.top.height.equalTo(editInfoBtn)
            make.left.equalTo(self.snp_centerX).offset(3)
            make.right.equalTo(0)
        }
        
        publishStatusBgView.snp_makeConstraints { (make) in
            
            make.top.equalTo(editInfoBtn.snp_bottom).offset(LDMargin_V*2)
            make.left.right.equalTo(0)
            make.height.equalTo(54)
        }
        
        let leftFloat:CGFloat = IPHONE6PLUSEUP ? 55 : IPHONE6UP ? 45:35

        publishStatusImage.snp_makeConstraints { (make) in
            
            make.centerY.equalTo(publishStatusBgView)
            make.left.equalTo(leftFloat)
            make.size.equalTo(CGSizeMake(25, 24))
            
        }
        publishStatusLabel.snp_makeConstraints { (make) in
            
            make.top.equalTo(15)
            make.left.equalTo(publishStatusImage.snp_right).offset(10)
            make.bottom.equalTo(-15)

        }

//        //底部布局
//        actTitle!.snp_makeConstraints { (make) in
//            
//            make.left.equalTo(0)
//            make.right.equalTo(self.snp_centerX)
//            
//            make.height.equalTo(15)
//            make.bottom.equalTo(-Margin_V*4)
//            
//        }
//        
//        focTitle!.snp_makeConstraints { (make) in
//            
//            make.left.equalTo(actTitle!.snp_right)//equalTo(self.snp_centerX)
//            make.right.equalTo(0)
//            
//            make.bottom.height.equalTo(actTitle!)
//        }
//        
//        activityLab.snp_makeConstraints { (make) in
//            make.left.right.width.equalTo(actTitle!)
//            
//            make.bottom.equalTo(actTitle!.snp_top).offset(-LDMargin_V)
//            make.height.equalTo(30)
//            
//        }
//        
//        focusLab.snp_makeConstraints { (make) in
//            
//            make.left.right.width.equalTo(focTitle!)
//            make.centerX.equalTo(focTitle!)
//            make.bottom.height.equalTo(activityLab)
//        }
//        
        coverView?.snp_makeConstraints(closure: { (make) in
            
            make.left.right.equalTo(0)
            make.height.equalTo(70)
            make.bottom.equalTo(-Margin_V * 2)
        })
        
//        //bottom divideline
//        let bottomLine = UIView()
//        bottomLine.backgroundColor = LDLineColorLightGray
//        coverView?.addSubview(bottomLine)
//        bottomLine.snp_makeConstraints { (make) in
//            
//            make.centerX.equalTo(self)
//            make.top.equalTo(5)
//            make.bottom.equalTo(-5)
//            make.width.equalTo(0.5)
//        }
        
        let bottomcover = UIView()//遮盖shaow
        bottomcover.backgroundColor = LDGolbalColor.BgGoundGray
        addSubview(bottomcover)
        bottomcover.snp_makeConstraints { (make) in
            
            make.top.equalTo(coverView!.snp_bottom)
            make.left.right.equalTo(0)
            make.bottom.equalTo(0)
        }
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
